<cfset errormsg = "">
<cfset errorfields = "">
<cfset waserror = 0>
<cfif formaction IS 'Add'>
  <!---adding account so make sure there is no duplicate email address--->
  <cfquery name = "qryCheckEmail" datasource="#request.dsn#">
    SELECT * FROM core_accounts
    WHERE email = '#form.email#'
    </cfquery>
  <cfif qryCheckEmail.recordcount GT 0>
    <cfset waserror = 1>
    <cfset errormsg = request.lang.accounts.errors.missingfield>
  </cfif>
  <cfset new_username = replace(form.username, " ", "", "ALL")>
  <cfset new_username = replace(new_username, "-", "", "ALL")>
  <cfset new_username = replace(new_username, "*", "", "ALL")>
  <cfset new_username = replace(new_username, "/", "", "ALL")>
  <cfset new_username = replace(new_username, "\", "", "ALL")>
  <cfset new_username = replace(new_username, ",", "", "ALL")>
  <cfset new_username = replace(new_username, "'", "", "ALL")>
  <cfset new_username = replace(new_username, "&", "and", "ALL")>
  <cfset new_username = replace(new_username, "!", "", "ALL")>
  <cfset new_username = replace(new_username, "(", "", "ALL")>
  <cfset new_username = replace(new_username, ")", "", "ALL")>
  <cfset new_username = replace(new_username, "+", "", "ALL")>
  <cfset new_username = replace(new_username, "=", "", "ALL")>
  <cfset new_username = replace(new_username, "##", "", "ALL")>
  <cfset new_username = replace(new_username, "$", "", "ALL")>
  <cfset new_username = replace(new_username, "%", "", "ALL")>
  <cfset new_username = replace(new_username, "^", "", "ALL")>
  <cfset new_username = replace(new_username, "@", "", "ALL")>
  <cfquery name = "qDuplicate" datasource="#request.dsn#">
SELECT * FROM core_accounts
WHERE username = '#new_username#'
</cfquery>
  <cfif qDuplicate.recordcount GT 0>
    <cfset waserror = 1>
    <cfset errormsg = request.lang.accounts.error.usertaken>
  </cfif>
  <cfif len(trim(form.password)) IS 0>
    <cfset waserror = 1>
    <cfset errormsg = request.lang.accounts.errors.missingfield>
  </cfif>
</cfif>
<cfif len(trim(form.username)) LT 3>
  <cfset waserror = 1>
  <cfset errormsg = request.lang.accounts.errors.missingfield>
</cfif>
<cfif len(trim(form.firstname)) IS 0>
  <cfset waserror = 1>
  <cfset errormsg = request.lang.accounts.errors.missingfield>
</cfif>
<cfif len(trim(form.lastname)) IS 0>
  <cfset waserror = 1>
  <cfset errormsg = request.lang.accounts.errors.missingfield>
</cfif>
<cfif len(trim(form.email)) IS 0>
  <cfset waserror = 1>
  <cfset errormsg = request.lang.accounts.errors.missingfield>
</cfif>
<cfif len(trim(form.username)) IS 0>
  <cfset waserror = 1>
  <cfset errormsg = request.lang.accounts.errors.missingfield>
</cfif>
